<template>
  <el-select
    v-model="sourceValue"
    :placeholder="placeholder"
    :disabled="disabled"
    :style="{width: width + 'px'}"
    :clearable="clearable"
    @change="onChange"
  >
    <el-option
      v-for="item in dataSource"
      :key="item.lngdatasourceid"
      :label="item.strdatasourcename"
      :value="item.lngdatasourceid"
    />
  </el-select>
</template>

<script>
import { dataSource } from '@/api/common/common'
export default {
  name: 'DataSources',
  props: {
    value: {
      type: [String, Number],
      default: ''
    },
    placeholder: {
      type: String,
      default: '请选择'
    },
    disabled: {
      type: Boolean,
      default: false
    },
    width: {
      type: [String, Number],
      default: 110
    },
    clearable: {
      type: Boolean,
      default: true
    }
  },
  data() {
    return {
      dataSource: []
    }
  },
  computed: {
    sourceValue: {
      get() {
        return this.value
      },
      set(val) {
        this.$emit('input', val)
      }
    }
  },
  created() {
    this.getDataSource()
  },
  methods: {
    onChange(val) {
      this.$emit('change', val)
    },
    getDataSource() {
      dataSource({}).then(res => {
        if (res.code === 20000) {
          this.dataSource = res.data
        }
      })
    }
  }
}
</script>

<style scoped>

</style>
